package edu.ynmd.parm.action;


import edu.ynmd.parm.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class PublicAction {

    @RequestMapping("getAnString")
    @ResponseBody
    public String getAnString(){
        return "服务器返回的字符串";
    }


    //?key=value
    //http://localhost:81/passValueToServrByRequestParm?sid=abc123
    @GetMapping("passValueToServrByRequestParm")
    @ResponseBody
    public String passValueToServrByRequestParm(@RequestParam String sid){
        return sid+"服务器已收到";
    }

    @GetMapping("receivePathValue/{sid}")
    @ResponseBody
    public String receivePathVaue(@PathVariable(name="sid")String sid){
        return sid+"服务器已收到";
    }


    @PostMapping("receiveAnObject")
    @ResponseBody
    public Student receiveAnObject(@RequestBody Student student){
        return student;
    }
    //用于接收form表单提交的信息
    @PostMapping("receiveFormValue")
    @ResponseBody
    public Student receiveFormValue(Student student){
        return student;
    }


    @GetMapping("returnAnObjectList")
    @ResponseBody
    public List<Student> returnAnObjectList(){
        List<Student> sl=new ArrayList<>();
        for (int i=0;i<10;i++){
            Student s = new Student();
            s.setId("id+i");
            s.setStuid("stuid"+i);
            s.setName("name"+i);

            sl.add(s);
        }
        return sl;
    }


    @PostMapping("receiveAnList")
    @ResponseBody
    public List<Student> receiveAnList(@RequestBody List<Student> sl){
        return sl;
    }
}
